﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GUI.TraCuu_Update
{
    public partial class BaoCaoNoGUI : UserControl, GUI.UctrlGUI
    {
        BLL.DanhSachBaoCaoNoBLL _BaoCaoNoBLL;
        BLL.DanhSachKhachHangBLL _KhachHangBLL;

        public BaoCaoNoGUI()
        {
            InitializeComponent();
            _BaoCaoNoBLL = new BLL.DanhSachBaoCaoNoBLL();
            _KhachHangBLL = new BLL.DanhSachKhachHangBLL();
        }

        public String getName()
        {
            return "TRA CỨU BÁO CÁO CÔNG NỢ";
        }

        private void InitThang()
        {
            String[] range = new String[12];
            for (int i = 0; i < 12; i++)
                range[i] = (i + 1).ToString();
            cbx_Thang.Items.AddRange(range);
            cbx_Thang.SelectedIndex = 0;
        }

        private void UpdateGV()
        {
            gv_List.Rows.Clear();
            List<DTO.BaoCaoNoThangDTO> lis = 
                _BaoCaoNoBLL.SelectByThang(cbx_Thang.SelectedIndex + 1);
            foreach (DTO.BaoCaoNoThangDTO dto in lis)
            {
                DTO.KhachHangDTO khdto = _KhachHangBLL.GetKhachHangByID(dto.IDKhachHang);
                String[] gvitem = new String[] { 
                    (gv_List.Rows.Count + 1).ToString(),
                    dto.IDKhachHang.ToString(),
                    khdto.HoTen,
                    dto.NoDau.ToString(),
                    dto.PhatSinh.ToString(),
                    dto.NoCuoi.ToString()
                };
                gv_List.Rows.Add(gvitem);
            }
        }

        private void BaoCaoNoGUI_Load(object sender, EventArgs e)
        {
            InitThang();
        }

        private void cbx_Thang_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdateGV();
        }
    }
}
